#pragma once

#include "stm32f1xx_hal.h"

#ifdef __cplusplus
extern "C" {
#endif

// LED1 GPIO Configuration
// PD2 ==> LED1
#define LED_PERIPHERAL_CLK_ENABLE()	__HAL_RCC_GPIOD_CLK_ENABLE()
#define LED_PORT    GPIOD
#define LED_PIN     GPIO_PIN_2

__STATIC_INLINE void LED_Init(void)
{
	LED_PERIPHERAL_CLK_ENABLE();

	GPIO_InitTypeDef GPIO_InitStruct = {0};
    GPIO_InitStruct.Pin = LED_PIN;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
}

__STATIC_INLINE void LED_On(void)
{
    HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_RESET);
}

__STATIC_INLINE void LED_Off(void)
{
    HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_SET);
}

__STATIC_INLINE void LED_Toggle(void)
{
    HAL_GPIO_TogglePin(LED_PORT, LED_PIN);
}

#ifdef __cplusplus
}
#endif
